package com.songlanyun.modules.exception;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.songlanyun.common.drive.IntegerEnum;

import java.util.Objects;

public enum MarketingException implements IntegerEnum<Integer> {

    CYCLE_TYPE_ERROR(32001, "请选择正确的周期方式"),
    FIRST_ORDER_EXIST(32002, "该商家已存在首单优惠"),
    FIRST_ORDER_NOT_EXIST(32003, "该首单优惠不存在"),
    SALE_EXCEPTION(32004, "可售数量与初始化销量之和不能小于已售数量"),

    SECKILL_ACTIVITY_TIME_USEING(32101, "秒杀活动时间已被使用"),
    SECKILL_ACTIVITY_ERROR(32102, "秒杀活动时间填写错误"),
    SECKILL_ACTIVITY_NAME_REPETITION(32103, "秒杀活动的名称不能重复"),
    SECKILL_ACTIVITY_NOT_EXIST(32104, "秒杀活动不存在"),
    SECKILL_ACTIVITY_UNDERWAY(32105, "秒杀活动正在进行中，不能操作"),
    SECKILL_ACTIVITY_GOODS_UNDERSTOCK(32106, "秒杀活动商品库存不足"),
    SECKILL_ACTIVITY_GOODS_NOT_EXIST(32105, "秒杀活动商品不存在"),
    SECKILL_ACTIVITY_GOODS_EXIST(32106, "该秒杀活动中存在秒杀活动商品，不能删除"),
    SECKILL_ACTIVITY_GOODS__NOT_DEL(32107, "该秒杀活动已开启，则秒杀活动商品不能被删除"),
    SECKILL_ACTIVITY_FINISH(32108, "秒杀活动已结束，不能操作"),
    SECKILL_ACTIVITY_START(32109, "秒杀活动已开始，不能操作"),

    GROUP_BUY_ACTIVITY_NOT_EXIST(32201, "拼团活动不存在"),
    GROUP_BUY_ACTIVITY_UNDERWAY(32202, "拼团活动正在进行中，不能操作"),
    GROUP_BUY_ACTIVITY_FINISH(32203, "拼团活动已结束，不能操作"),

    GROUP_BUY_ACTIVITY_NAME_REPETITION(32204, "拼团活动的名称不能重复"),
    GROUP_BUY_ACTIVITY_GOODS_UNDERSTOCK(32205, "拼团活动商品库存不足"),
    GROUP_BUY_ACTIVITY_GOODS_NOT_EXIST(32206, "拼团活动商品不存在"),
    GROUP_BUY_ACTIVITY_GOODS_PRICE_ERROR(32207, "活动商品的活动价不能大于商品销售价"),
    DISCOUNT_OUT_OF_RANGE(32208, "固定折扣不在范围"),
    FIXPRICE_OUT_OF_RANGE(32209, "固定减价不在范围"),
    ACTIVITY_PRICE_OUT_OF_RANGE(32210, "活动价格不在范围"),
    GROUP_BUY_ACTIVITY_TIME_USEING(32211, "拼团活动时间已被使用"),
    GROUP_BUY_ACTIVITY_GOODS__NOT_DEL(32212, "该拼团活动已开启，则拼团活动商品不能被删除"),
    GROUP_BUY_ACTIVITY_GOODS_EXIST(32213, "该拼团活动中存在秒杀活动商品，不能删除"),
    ACTIVITY_PRICE_LT_SALE_PRICE(32214, "活动价格需要小于原价"),
    REAL_STOCK_TOTAL_LT_INIT_SALE_NUM(32215, "可售数量应大于初始化销量"),


    INCORRECT_PARAMETER_PASSED_IN(32216, "传入参数有误"),
    GROUP_BUY_ACTIVITY_GOODS_SKU_ERROR(32217, "活动商品的商品规则与原商品规格不在有交集"),



    ;

    private Integer code;
    private String msg;

    MarketingException(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @JsonCreator
    public static MarketingException getByCode(int code) {
        for (MarketingException value : MarketingException.values()) {
            if (Objects.equals(code, value.getCode())) {
                return value;
            }
        }
        return null;
    }
}
